# routers/recordings.py
import logging
from fastapi import APIRouter, Depends, UploadFile, File, BackgroundTasks
from http_base import unified_resp
from ..schemas.meetings_recording import (
    MeetingsRecordingEditIn, MeetingsRecordingDelIn, MeetingsRecordingListIn, MeetingsRecordingDetailIn
)
from ..service.meetings.meetings_recording import IMeetingsRecordingService

logger = logging.getLogger(__name__)
router = APIRouter(prefix="/recordings")


@router.post("/list", summary="录音列表")
@unified_resp
async def recording_list(list_in: MeetingsRecordingListIn, svc: IMeetingsRecordingService = Depends()):
    return await svc.list(list_in)


@router.get("/detail", summary="录音详情")
@unified_resp
async def recording_detail(detail_in: MeetingsRecordingDetailIn = Depends(), svc: IMeetingsRecordingService = Depends()):
    return await svc.detail(detail_in.id)


@router.post("/add", summary="上传录音")
@unified_resp
async def recording_add(mid: int, file: UploadFile = File(...), background_tasks: BackgroundTasks = None, svc: IMeetingsRecordingService = Depends()):
    # 此路由演示文件上传 -> service 负责保存元数据并入队转录
    return await svc.upload_file(mid, file, background_tasks)


@router.post("/edit", summary="编辑录音元数据")
@unified_resp
async def recording_edit(edit_in: MeetingsRecordingEditIn, svc: IMeetingsRecordingService = Depends()):
    return await svc.edit(edit_in)


@router.post("/del", summary="删除录音")
@unified_resp
async def recording_del(del_in: MeetingsRecordingDelIn, svc: IMeetingsRecordingService = Depends()):
    return await svc.delete(del_in.id)
